<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item>
          <el-date-picker v-model="dateRange" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item> -->

      <el-form-item label="车号" prop="chehao">
        <el-input
          v-model="queryParams.chehao"
          placeholder="请输入车号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="称重编号" prop="czbh">
        <el-input
          v-model="queryParams.czbh"
          placeholder="请输入称重编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料名称 " prop="wlmc">
        <el-input
          v-model="queryParams.wlmc"
          placeholder="请输入物料名称 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="制单人员" prop="fk_zdr">
        <el-input
          v-model="queryParams.fk_zdr"
          placeholder="请输入制单人 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <br />
      <el-form-item>
        <el-checkbox :true-label="'是'" :false-label="'否'" v-model="shym">
          散户玉米
        </el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-checkbox :true-label="'是'" :false-label="'否'" v-model="syym">
          所有玉米
        </el-checkbox>
      </el-form-item>

      <el-form-item>
        <el-select
          v-model="selectedValue1"
          placeholder="请选择出入库"
          clearable
        >
          <el-option label="入库" :value="1"></el-option>
          <el-option label="出库" :value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-select
          v-model="selectedValue2"
          placeholder="请选择是否进厂"
          clearable
        >
          <el-option label="所有车辆" :value="1"></el-option>
          <el-option label="待进厂" :value="2"></el-option>
          <el-option label="已进厂" :value="3"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:guozhong:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!-- v-loading="loading" -->
    <el-table
      v-loading="loading"
      :data="zaichangList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="称重编号" align="center" prop="czbh" />
      <el-table-column label="卡号" align="center" prop="card_id" />
      <el-table-column label="车号" align="center" prop="chehao" />
      <el-table-column label="发货方" align="center" prop="gysdm" />
      <el-table-column label="收货方" align="center" prop="gsmc" />
      <el-table-column label="物料名" align="center" prop="wlmc" />
      <el-table-column label="仓库编号" align="center" prop="ckbh" />
      <el-table-column label="仓库名" align="center" prop="ckmc" />
      <el-table-column label="进厂重量" align="center" prop="mz" />
      <el-table-column label="进厂时间" align="center" prop="mzsj" />
      <el-table-column label="结算单价" align="center" prop="jsdj" />
      <el-table-column label="容重数量" align="center" prop="rzsl" />
      <el-table-column label="容重等级" align="center" prop="rzdj" />
      <el-table-column label="进厂地磅" align="center" prop="dbh" />
      <el-table-column label="出厂地磅" align="center" prop="dbh2" />
      <el-table-column label="制单人员" align="center" prop="fk_zdr" />
      <el-table-column label="粮食性质" align="center" prop="jshth" />
      <el-table-column label="卸车部门" align="center" prop="xcbm" />
      <el-table-column label="供应商名" align="center" prop="gysdm" />
      <el-table-column label="公司名" align="center" prop="gsmc" />
      <el-table-column label="内外销" align="center" prop="sd_dwx" />
      <el-table-column label="包装物名" align="center" prop="sd_bzwmc" />
      <el-table-column label="预发吨位" align="center" prop="ddwlsl" />
      <el-table-column label="原始净重" align="center" prop="ddysjz" />
      <el-table-column label="发卡时间" align="center" prop="fksj" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
  
  <script>
import { listZaiChangInfo } from "@/api/system/Fdongbei/zaichang";

export default {
  name: "Guozhong",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // tb表格数据
      zaichangList: [],
      // 化验--》表格数据
      tbHuayanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chehao: null,
        czbh: null,
        wlmc: null,
        fk_zdr: null,
        chuRuKu: null,
        jinChang: null,
        bj: null,
      },
      selectedValue1: null,
      selectedValue2: null,
      shym: null,
      syym: null,
      // 表单参数
      form: {},
      // 表单校
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //设置默认时间

    // 默认时间
    // timeDefault() {
    //   let date = new Date();

    //   // 通过时间戳计算
    //   let defalutStartTime = date.getTime() - 7 * 24 * 3600 * 1000; // 转化为时间戳
    //   let defalutEndTime = date.getTime();

    //   let startDateNs = new Date(defalutStartTime);
    //   let endDateNs = new Date(defalutEndTime);

    //   // 月，日，时，分，秒 不够10补0
    //   defalutStartTime =
    //     startDateNs.getFullYear() +
    //     "-" +
    //     (startDateNs.getMonth() + 1 >= 10
    //       ? startDateNs.getMonth() + 1
    //       : "0" + (startDateNs.getMonth() + 1)) +
    //     "-" +
    //     (startDateNs.getDate() >= 10
    //       ? startDateNs.getDate()
    //       : "0" + startDateNs.getDate()) +
    //     " " +
    //     (startDateNs.getHours() >= 10
    //       ? startDateNs.getHours()
    //       : "0" + startDateNs.getHours()) +
    //     ":" +
    //     (startDateNs.getMinutes() >= 10
    //       ? startDateNs.getMinutes()
    //       : "0" + startDateNs.getMinutes()) +
    //     ":" +
    //     (startDateNs.getSeconds() >= 10
    //       ? startDateNs.getSeconds()
    //       : "0" + startDateNs.getSeconds());

    //   defalutEndTime =
    //     endDateNs.getFullYear() +
    //     "-" +
    //     (endDateNs.getMonth() + 1 >= 10
    //       ? endDateNs.getMonth() + 1
    //       : "0" + (endDateNs.getMonth() + 1)) +
    //     "-" +
    //     (endDateNs.getDate() >= 10
    //       ? endDateNs.getDate()
    //       : "0" + endDateNs.getDate()) +
    //     " " +
    //     (endDateNs.getHours() >= 10
    //       ? endDateNs.getHours()
    //       : "0" + endDateNs.getHours()) +
    //     ":" +
    //     (endDateNs.getMinutes() >= 10
    //       ? endDateNs.getMinutes()
    //       : "0" + endDateNs.getMinutes()) +
    //     ":" +
    //     (endDateNs.getSeconds() >= 10
    //       ? endDateNs.getSeconds()
    //       : "0" + endDateNs.getSeconds());

    //   return [defalutStartTime, defalutEndTime];
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询tb列表 */
    getList() {
      this.loading = true;
      if (this.shym == "是") {
        this.queryParams.bj = 1;
      }
      if (this.syym == "是") {
        this.queryParams.bj = 2;
      }
      listZaiChangInfo(this.queryParams).then((response) => {
        this.zaichangList = response.data.list;

        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        czbh: "",
        chehao: "",
        gysdm: "",
        ckbh: "",
      };
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.czbh);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/guozhong/export",
        {
          ...this.queryParams,
        },
        `guozhong_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>